package com.hankol.newretail.adapter

import android.util.TypedValue
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.baselibrary.extension.checkValue
import com.baselibrary.utils.GlideUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.MallTabBean

/*商品分类tab */
class MallTabAdapter : BaseQuickAdapter<MallTabBean, BaseViewHolder>(R.layout.item_mall_tab) {

    override fun convert(helper: BaseViewHolder, item: MallTabBean) {
        GlideUtils.loadImg_101(mContext, item.cover.checkValue(), helper.getView<ImageView>(R.id.img_cover))
        helper.setVisible(R.id.img_indicator, item.isSelect)
        val tvName = helper.getView<TextView>(R.id.tv_name)
        tvName.setTextColor(ContextCompat.getColor(mContext, if (item.isSelect) R.color.color_D53 else R.color.black))
        tvName.text = item.name.checkValue()
        tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, if (item.isSelect) 14f else 12f)
        tvName.paint.isFakeBoldText = item.isSelect
    }

    fun upSelected(position: Int) {
        for (index in 0 until data.size) {
            data[index].isSelect = position == index
        }
        notifyDataSetChanged()
    }
}